package app.domain.order;

import app.domain.order.util.OrderType;
import app.domain.order.util.Side;
import app.domain.order.util.Ticket;
import app.domain.order.util.Type;



public class Order {
	public final static double DELTA = 0.0001;
	private String clientId;
	private int referenceId;
	private double price;
	private int amount;
	private Side side;
	private Ticket ticket;
	private Type type;
	private OrderType orderType;

	private Order(String clientId, int referenceId, Ticket ticket, Type type, Side side, int amount, double price) {
		this.orderType = OrderType.NEW;
		this.clientId = clientId;
		this.referenceId = referenceId;
		this.ticket = ticket;
		this.amount = amount;
		this.side = side;
		this.type = type;
		if(type == Type.L) {
			this.price = (int)(price/DELTA)*DELTA;		
		} else {
			if (side == Side.B) {
				this.price = Double.MAX_VALUE;
			} else {
				this.price = 0;
			}
		}	
	}

	private Order(String clientId, int referenceId) {
		this.orderType = OrderType.CANCEL;
		this.clientId = clientId;
		this.referenceId = referenceId;
	}
	
	private Order(String clientId) {
		this.orderType = OrderType.DELETE_CLIENT;
		this.clientId = clientId;
	}
	
	public static Order createNewOrder(String clientId,int referenceId, Ticket ticket, Type type, Side side, int amount, double price) {
		return new Order(clientId,referenceId,ticket,type,side,amount,price);
	}
	
	public static Order createCancelOrder(String clientId, int referenceId) {
		return new Order(clientId,referenceId);
	}
	
	public static Order createDeleteClientOrder(String clientId) {
		return new Order(clientId);
	}
	
	public String getClientId() {
		return clientId;
	}
	
	public void changeAmount(int i) {
		this.amount -= i;
	}

	public int getAmount() {
		return amount;
	}

	public void setAmount(int amount) {
		this.amount = amount;
	}

	public double getPrice() {
		return price;
	}

	public Side getSide() {
		return side;
	}

	public Ticket getTicket() {
		return ticket;
	}

	public Type getType() {
		return type;
	}
	
	public OrderType getOrderType() {
		return orderType;
	}
	
	public int getReferenceId() {
		return referenceId;
	}
	
}
